var timer;
var timeoutHandler;
function startSlam(ros,name,type,data,callback,failure){
    cancelTimer();
    timeoutHandler= setTimeout(function(){
        cancelTimer();
        failure("请求超时")
    },15000);
    timer = setInterval(function(){
        startSlamService(ros,name,type,data,callback,failure)
    },1500)

}

function startSlamService(ros,name,type,data,callback,failure){
    ros.sendCustomService(name,type,data,function(result){
        console.log("startSlamService success,result is %o",result);//成功的回调
        if("success"==result.res){
          cancelTimer();
          callback(result);
        }else{
        //   alert("停止建图失败，错误信息:"+result.res)
        console.error("startSlamService success,result is %o",result);//失败的回调
        }
      },
      function(error){
        cancelTimer();
        console.error("start_slam fail msg %o",error);//失败的回调
        failure(error);
      });
}

function cancelTimer(){
    clearTimeout(timeoutHandler)
    clearInterval(timer);
}